////////////////////////////////////////////////////////////////////////////////
// Filename: mesh.h
////////////////////////////////////////////////////////////////////////////////
#ifndef _MESH_H_
#define _MESH_H_

#include <windows.h>
#include <xnamath.h>

#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <vector>

#include "CDirect3D.h"
#include "Texture.h"
#include "BasicEffect.h"
#include "Tools.h"

class Bone;
class ShadowMap;

struct VertexTypeTexture
{
	XMFLOAT3 position;
	XMFLOAT2 texture;
	XMFLOAT3 normal;
	float alpha;
};

class Mesh
{
public:
	Mesh();
	Mesh(const Mesh&);
	Mesh operator=(Mesh const&);
	~Mesh();

	bool Initialize(const aiMesh* paiMesh, Texture* pTexture, BasicEffect* pShader);
	void Dispose();
	void Render(const XMFLOAT4X4 &worldMatrix, const XMFLOAT4X4 &viewMatrix, const XMFLOAT4X4 &projectionMatrix);
	//void ShadowRender(ShadowMap* pShadowMap, const XMFLOAT4X4 &worldMatrix);

	XMFLOAT3 GetCenter();

	void GetBoundingBox(BoundingBox &pBoundingBox, XMFLOAT4X4 &pTransform);

	bool IsTextureTransparent();
	std::string GetName();
	int GetIndex();
	void SetIndex(int pIndex);
	void SetParentIndex(Mesh* pParent);

	void SetBone(Bone* pBone);
	Bone* GetBone();

	void SetOrigine(XMFLOAT3 &pOrigine);
	XMFLOAT3* GetOrigine();

	void IASetVertices();
	void IASetIndices();
	void IASetTexture();
	int GetIndicesCount();
private:
	void RenderBuffers(ID3D11DeviceContext*);

	ID3D11DeviceContext* mDeviceContext;

	std::string mName;
	int mIndex;

	ID3D11Buffer *m_vertexBuffer, *m_indexBuffer;
	int m_vertexCount, m_indexCount;
	Texture* mTexture;
	XMFLOAT3 mCenter;
	XMFLOAT3 mOrigine;
	BasicEffect* mShader;
	std::vector<XMFLOAT3> mVertices;

	Bone* mBone;
};

#endif
